package health.lm.com.mine.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.androidkun.xtablayout.XTabLayout;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.mine.R;
import health.lm.com.mine.R2;
import health.lm.com.mine.adapter.ThinkTanklPagerAdapter;
import health.lm.com.mine.entity.ThinkTankEntity;
import health.lm.com.mine.present.ThinkTankPresenter;
import health.lm.com.router.ARouterConstant;

import static com.lm.sjy.titlebar.widget.CommonTitleBar.ACTION_LEFT_BUTTON;

/**
 * 智库
 *
 * @author GQI
 */
@Route(path = ARouterConstant.ThinkTankActivity)
public class ThinkTankActivity extends XActivity<ThinkTankPresenter> {
    @BindView(R2.id.title_bar)
    CommonTitleBar titlebar;
    @BindView(R2.id.xTablayout)
    XTabLayout xTablayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    private List<ThinkTankEntity.Category_list> entities;

    @Override
    public int getLayoutId() {
        return R.layout.activity_think_tank;
    }

    @Override
    public ThinkTankPresenter newP() {
        return new ThinkTankPresenter();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        titlebar.setListener((v, action, extra) -> {
            if (action == ACTION_LEFT_BUTTON) {
                finish();
            }
        });
        getP().getColumn();
    }


    public void getColumn(List<ThinkTankEntity.Category_list> entities) {
        this.entities = entities;
        ThinkTanklPagerAdapter adapter = new ThinkTanklPagerAdapter(getSupportFragmentManager(), entities);
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        xTablayout.setxTabDisplayNum(entities.size());
        //将TabLayout和ViewPager关联起来。
        xTablayout.setupWithViewPager(viewPager);
    }

}
